package org.dragonnova.meetingapp.model.bean;

import android.net.Uri;

import com.google.gson.GsonBuilder;

import org.dragonnova.meetingapp.utils.Constants;
import org.dragonnova.meetingapp.utils.LogUtil;

import java.io.Serializable;
import java.util.Random;

/**
 * Created by hucn on 2016/5/26.
 * Description: 会议的数据结构
 */
public class MeetingInfo implements Serializable {

    public static final String CONTENT = "meeting";
    public final static Uri CONTENT_MEETING_URI = Uri.parse("content://" + Constants.AUTHORITY + "/" + CONTENT);

    public final static String KEY_ID_COLUMN = "_id";
    public final static String KEY_SERIAL_COLUMN = "serial";
    public static final String KEY_START_TIME_COLUMN = "START_TIME";
    public static final String KEY_END_TIME_COLUMN = "END_TIME";
    public static final String KEY_DURATION_COLUMN = "DURATION";
    public static final String KEY_NAME_COLUMN = "NAME";
    public static final String KEY_PASSWORD_COLUMN = "PASSWORD";
    public static final String KEY_FLAG_COLUMN = "FLAG";

    private long id;

    private long serial;

    private long startTime;

    private long endTime;

    private long duration;

    private String name;

    private String password;

    private int flag;


    public MeetingInfo() {

    }

    public MeetingInfo(long serial, String name, String password) {
        this.serial = serial;
        this.name = name;
        this.password = password;
    }

    public MeetingInfo(long id, long startTime, long endTime, long duration, String name, String password, int flag) {

    }

    public MeetingInfo(long id, long serial, long startTime, long endTime, long duration, String name, String password, int flag) {
        this.id = id;
        this.serial = serial;
        this.startTime = startTime;
        this.endTime = endTime;
        this.duration = duration;
        this.name = name;
        this.password = password;
        this.flag = flag;
    }

    public long getId() {
        return id;
    }

    public void setId(long id) {
        this.id = id;
    }

    public long getSerial() {
        return serial;
    }

    public void setSerial(long serial) {
        this.serial = serial;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public long getEndTime() {
        return endTime;
    }

    public void setEndTime(long endTime) {
        this.endTime = endTime;
    }

    public long getDuration() {
        return duration;
    }

    public void setDuration(long duration) {
        this.duration = duration;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getFlag() {
        return flag;
    }

    public void setFlag(int flag) {
        this.flag = flag;
    }

    public byte[] encode() {
        String msg = new GsonBuilder().create().toJson(this);
        LogUtil.eee("meetingInfo ======" + msg);
        return msg.getBytes();
    }

    public static MeetingInfo parse(String json) {
        return new GsonBuilder().create().fromJson(json, MeetingInfo.class);
    }

    @Override
    public String toString() {
        return "MeetingInfo{" +
                "id=" + id +
                ", serial=" + serial +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", duration=" + duration +
                ", name='" + name + '\'' +
                ", password='" + password + '\'' +
                ", flag=" + flag +
                '}';
    }

    public static int getRandomId() {
        Random random = new Random();
        return random.nextInt(Integer.MAX_VALUE)%(Integer.MAX_VALUE/2) + Integer.MAX_VALUE/2;
    }
}
